package com.lap.auth.adapter.driven.web.role;

import com.lap.auth.application.role.RoleAppService;
import com.lap.auth.application.role.command.CreateRoleCmd;
import com.lap.auth.application.role.command.UpdateRoleCmd;
import com.lap.auth.application.role.dto.QueryRolePageQuery;
import com.lap.auth.application.role.dto.RoleDto;
import com.lap.framework.dto.page.PageResponse;
import com.lap.watchdog.starter.annotation.RepeatSubmit;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Tag(name = "角色管理", description = "提供角色基本操作，查询等")
@RequiredArgsConstructor
@RestController
@RequestMapping("api/v1/roles")
public class RoleController {

  private final RoleAppService roleAppService;

  @Operation(summary = "获取角色")
  @GetMapping
  public PageResponse<RoleDto> getRolePage(QueryRolePageQuery query) {
    return roleAppService.queryRolesByPage(query);
  }

  @Operation(summary = "添加角色")
  @RepeatSubmit
  @PostMapping
  public Integer createRole(@RequestBody @Valid CreateRoleCmd cmd) {
    return roleAppService.createRole(cmd);
  }

  @Operation(summary = "更新角色")
  @RepeatSubmit
  @PutMapping("{id}")
  public Integer updateRole(@PathVariable Integer id, @RequestBody @Valid UpdateRoleCmd cmd) {
    return roleAppService.updateRole(id, cmd);
  }

  @Operation(summary = "删除角色")
  @RepeatSubmit
  @DeleteMapping("{id}")
  public Integer deleteRole(@PathVariable Integer id) {
    return roleAppService.deleteRole(id);
  }
}
